package com.lgj.demo0812.singleton;

/**
 * @author lizy51
 * @date 2022-09-07 16:59
 */
public class LazyMan {
    private LazyMan(){
        System.out.println(Thread.currentThread().getName());
    }

    private volatile static LazyMan lazyMan; //防止指令重排

    public static LazyMan getInstance(){
       if (lazyMan == null){
           synchronized (LazyMan.class){
               if (lazyMan == null){
                   lazyMan = new LazyMan();
               }
           }
       }
        return lazyMan;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                LazyMan.getInstance();
            }).start();
        }
    }
}
